﻿using DevExpress.Mvvm;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using TestingApp.Models;
using TestingApp.Pages.Admin;
using TestingApp.Services;

namespace TestingApp.ViewModels.Admin
{
    public class AdminPageViewModel : BindableBase {

        private readonly PageService _navigation;
        private readonly Repository _repository;

        public ObservableCollection<Test> Tests { get; set; } = new ObservableCollection<Test>();

        public AdminPageViewModel(PageService navigation, Repository repository)  {

            Tests = new ObservableCollection<Test>(repository.FindAll<Test>());

           

            Tests.Add(new Test   {
                QuestionCount = 3,
                Title = "Тест по Физике",
            });
            _navigation = navigation;
            _repository = repository;
        }

        public ICommand AddTest => new DelegateCommand(() => {
            _navigation.Navigate(new TestEditorPage());        
        });

        public ICommand OpenTest => new DelegateCommand(()=> { 

            ///TODO  реализовать открытие теста на редактирование
        });

        public ICommand RemoveTest => new DelegateCommand<Test>((test)=> {            
            Tests.Remove(test);

        },  (test)=> test != null);       

    }
}
